import pickle


my_instance=100
# 将实例序列化为一个字符串
serialized_instance = pickle.dumps(my_instance)
# 将字符串写入到一个文件中
with open('my_instance.txt', 'wb') as f:
    f.write(serialized_instance)# 打开文件


with open('my_instance.txt', 'rb') as f:
    # 读取文件内容
    serialized_instance = f.read()

# 使用pickle模块反序列化对象
my_instance = pickle.loads(serialized_instance)

# 现在你可以访问my_instance的属性了
print(my_instance)


